package com.ict.ms.trackPlayBack.service.redis.redisService;

import com.ict.ms.trackPlayBack.facade.redis.dao.IUserTestDao;
import com.ict.ms.trackPlayBack.facade.redis.pojo.UserTest;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

/**
 * Created by chenlong on 2016/11/9.
 */
@Service
public class UserTestService {

    public boolean SaveUser(UserTest userTest){
        try {
            ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/applicationContext3.xml");
            IUserTestDao userDao = (IUserTestDao)ac.getBean("userTestDAO");
            userDao.save(userTest);
            System.out.println(userTest);
            return true;
        }catch (Exception e){
            System.out.println("Redis操作错误："+e);
            return false;
        }
    }

    public UserTest getUserTest(String uid){
        try {
            ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/applicationContext3.xml");
            IUserTestDao userDao = (IUserTestDao)ac.getBean("userTestDAO");
            UserTest userTest = userDao.read(uid);
            System.out.println(userTest);
            return userTest;
        }catch (Exception e){
            System.out.println("Redis操作错误："+e);
            return null;
        }
    }

    public UserTest UpdateUserTest(UserTest userTest){
        try{
            ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/applicationContext3.xml");
            IUserTestDao userDao = (IUserTestDao)ac.getBean("userTestDAO");

            userTest.setAddress(userTest.getAddress());
            userDao.save(userTest);
            System.out.println(userTest);
            return userTest;
        }catch (Exception e){
            System.out.println("Redis操作错误："+e);
            return null;
        }
    }

    public boolean DeleteUserTest(String uid){
        try{
            ApplicationContext ac =  new ClassPathXmlApplicationContext("classpath:/applicationContext3.xml");
            IUserTestDao userDao = (IUserTestDao)ac.getBean("userTestDAO");
            userDao.delete(uid);
            UserTest userTest = userDao.read(uid);
            System.out.println(userTest);
            return true;
        }catch (Exception e){
            System.out.println("Redis操作错误："+e);
            return false;
        }
    }
}
